package com.ayoka.parenting.ui.grown.list;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ayoka.parenting.Constants;
import com.ayoka.parenting.R;
import com.ayoka.parenting.adapter.AllGrownClassroomAdapter;
import com.ayoka.parenting.bean.ClassroomBean;
import com.ayoka.parenting.databinding.FragmentBaseRecyclerviewBinding;
import com.ayoka.parenting.mvp.MVPBaseActivity;
import com.ayoka.parenting.mvp.MVPBaseRecyclerViewFragment;
import com.ayoka.parenting.ui.grown.detail.GrownDetailActivity;
import com.jincp.common.brvah.BaseQuickAdapter;
import com.jincp.common.brvah.BaseViewHolder;
import com.jincp.common.utils.LiveDataBus;

import java.util.List;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: GrownFragment.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class GrownListFragment extends MVPBaseRecyclerViewFragment<ClassroomBean, FragmentBaseRecyclerviewBinding, GrownListContract.View, GrownListPresenter> implements GrownListContract.View {

    public static GrownListFragment newInstance(int classroomType) {
        GrownListFragment fragment = new GrownListFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("ClassroomType", classroomType);
        fragment.setArguments(bundle);
        return fragment;
    }

    private int classroomType;

    @Override
    protected void configBundleArguments() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            classroomType = bundle.getInt("ClassroomType", Constants.ClassroomType.TEST);
        }
    }

    @Override
    protected int getContentLayout() {
        return R.layout.fragment_base_recyclerview;
    }

    @Override
    protected SwipeRefreshLayout getRefreshLayout() {
        return mDataBinding.swipeRefresh;
    }

    @Override
    protected RecyclerView getRecyclerView() {
        return mDataBinding.recyclerView;
    }

    @NonNull
    @Override
    protected BaseQuickAdapter<ClassroomBean, BaseViewHolder> getAdapter() {
        AllGrownClassroomAdapter adapter = new AllGrownClassroomAdapter();
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                ClassroomBean classroomBean = (ClassroomBean) adapter.getItem(position);
                GrownDetailActivity.start(getActivity(), classroomBean.ID);
            }
        });
        return adapter;
    }

    @Override
    protected RecyclerView.ItemDecoration getRecycleDivider() {
        return null;
    }

    @Override
    protected void getData(boolean isShowWaitDialog) {
        if (mPresenter != null) {
            mPresenter.getAllClassRoomListData(classroomType);
        }
    }

    @Override
    protected void initData() {
        getData(true);
    }

    @Override
    protected GrownListPresenter getPresenter() {
        return new GrownListPresenter();
    }

    @Override
    public void configAllClassRoomListData(List<ClassroomBean> listData) {
        setLoadMoreLayout(listData);
    }

}
